package at.main.gui;

import at.main.android.Graphics;
import at.main.util.AllImage;
import at.main.util.AllSound;
import at.main.util.ManagerFont;

public class OptionPage {

	public static boolean isSoundBackground = true;

	public int iSelectMenu = 0;

	public OptionPage() {
		isSoundBackground = SoundPage.isSound;
	}

	public void paint(Graphics g) {
		g.setClip(0, 0, MyCanvas.iWidth, MyCanvas.iHeight);
		g.setColor(0x87CEFF);
		g.fillRect(0, 0, MyCanvas.iWidth, MyCanvas.iHeight);

		if (SoundPage.isSound) {
			ManagerFont.drawString(g, "Mở âm thanh game : Bật",
					MyCanvas.iWidth / 2, MyCanvas.iHeight / 3, 2,
					((0 - iSelectMenu) == 0 ? 1 : 2));
		} else {
			AllSound.Stop();
			ManagerFont.drawString(g, "Mở âm thanh game : Tắt",
					MyCanvas.iWidth / 2, MyCanvas.iHeight / 3, 2,
					((0 - iSelectMenu) == 0 ? 1 : 2));
		}
		if (isSoundBackground)
			ManagerFont.drawString(g, "Mở âm thanh nền : Bật",
					MyCanvas.iWidth / 2, MyCanvas.iHeight / 3 + 30, 2,
					((1 - iSelectMenu) == 0 ? 1 : 2));
		else
			ManagerFont.drawString(g, "Mở âm thanh nền : Tắt",
					MyCanvas.iWidth / 2, MyCanvas.iHeight / 3 + 30, 2,
					((1 - iSelectMenu) == 0 ? 1 : 2));

		if (AllImage.img_again != null) {
			g.drawImage(AllImage.img_again, MyCanvas.iWidth
					- AllImage.img_again.getWidth(), MyCanvas.iHeight
					- AllImage.img_again.getHeight(), Graphics.TOP
					| Graphics.LEFT);
		}
	}

	public void update() {
		// Left
		if (MyCanvas.keyHold[4]) {
			if (iSelectMenu == 0) {
				SoundPage.isSound = !SoundPage.isSound;
				isSoundBackground = SoundPage.isSound;
			} else if(SoundPage.isSound ){
				isSoundBackground = !isSoundBackground;
			}
		}
		// Right
		if (MyCanvas.keyHold[6]) {
			if (iSelectMenu == 0) {
				SoundPage.isSound = !SoundPage.isSound;
				isSoundBackground = SoundPage.isSound;
			} else if(SoundPage.isSound ){
				isSoundBackground = !isSoundBackground;
			}
		}
		// Up
		if (MyCanvas.keyHold[2]) {
			iSelectMenu--;
			if (iSelectMenu < 0)
				iSelectMenu = 1;

		}
		// Down
		if (MyCanvas.keyHold[8]) {
			iSelectMenu++;
			if (iSelectMenu > 1)
				iSelectMenu = 0;
		}
		if (MyCanvas.keyHold[13]) {
			if (PlayGame.isPause)
				MyCanvas.iCurrentPage = MyCanvas.k_MenuPlaying;
			else
				MyCanvas.iCurrentPage = MyCanvas.k_MenuPage;
			MyCanvas.clearInput();
		}
		MyCanvas.clearInput();
	}
}
